package org.theonept.travian.t4a.account;

import java.util.List;

import org.theonept.travian.model.Compte;
import org.theonept.travian.t4a.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListCompteAdapter extends ArrayAdapter<Compte> {
	private List<Compte> data;
	private Activity context;

	public ListCompteAdapter(Activity context, List<Compte> data) {

		super(context, android.R.id.text1, data);
		this.context = context;
		this.data = data;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Compte getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return data.get(position).getIdCompte();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Compte compte = data.get(position);
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.compte_list_view, parent,
				false);
		ImageView raceIcon = (ImageView) rowView.findViewById(R.id.compte_icon_race);
		TextView textPseudo = (TextView) rowView.findViewById(R.id.compte_pseudo_ligne);
		TextView textServeur = (TextView) rowView.findViewById(R.id.compte_serveur_ligne);
		textServeur.setText(compte.getUrlServeur());
		textPseudo.setText(compte.getUsername().toUpperCase());
		raceIcon.setImageResource(compte.getRace().getIdImage());
		return rowView;
	}
	

}
